﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Experimental.GlobalIllumination.Lightmapping
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Experimental.GlobalIllumination
{
  /// <summary>
  ///   <para>Interface to the light baking backends.</para>
  /// </summary>
  public static class Lightmapping
  {
    [RequiredByNativeCode]
    private static readonly Lightmapping.RequestLightsDelegate s_DefaultDelegate = (Lightmapping.RequestLightsDelegate) ((requests, lightsOutput) =>
    {
      DirectionalLight directionalLight = new DirectionalLight();
      PointLight pointLight = new PointLight();
      SpotLight spotLight = new SpotLight();
      RectangleLight rectangleLight = new RectangleLight();
      DiscLight discLight = new DiscLight();
      Cookie cookie = new Cookie();
      LightDataGI lightDataGi = new LightDataGI();
      for (int index = 0; index < requests.Length; ++index)
      {
        Light request = requests[index];
        switch (request.type)
        {
          case UnityEngine.LightType.Spot:
            LightmapperUtils.Extract(request, ref spotLight);
            LightmapperUtils.Extract(request, out cookie);
            lightDataGi.Init(ref spotLight, ref cookie);
            break;
          case UnityEngine.LightType.Directional:
            LightmapperUtils.Extract(request, ref directionalLight);
            LightmapperUtils.Extract(request, out cookie);
            lightDataGi.Init(ref directionalLight, ref cookie);
            break;
          case UnityEngine.LightType.Point:
            LightmapperUtils.Extract(request, ref pointLight);
            LightmapperUtils.Extract(request, out cookie);
            lightDataGi.Init(ref pointLight, ref cookie);
            break;
          case UnityEngine.LightType.Area:
            LightmapperUtils.Extract(request, ref rectangleLight);
            LightmapperUtils.Extract(request, out cookie);
            lightDataGi.Init(ref rectangleLight, ref cookie);
            break;
          case UnityEngine.LightType.Disc:
            LightmapperUtils.Extract(request, ref discLight);
            LightmapperUtils.Extract(request, out cookie);
            lightDataGi.Init(ref discLight, ref cookie);
            break;
          default:
            lightDataGi.InitNoBake(request.GetInstanceID());
            break;
        }
        lightsOutput[index] = lightDataGi;
      }
    });
    [RequiredByNativeCode]
    private static Lightmapping.RequestLightsDelegate s_RequestLightsDelegate = Lightmapping.s_DefaultDelegate;

    [RequiredByNativeCode]
    public static void SetDelegate(Lightmapping.RequestLightsDelegate del)
    {
      Lightmapping.s_RequestLightsDelegate = del != null ? del : Lightmapping.s_DefaultDelegate;
    }

    /// <summary>
    ///   <para>Get the currently set conversion delegate.</para>
    /// </summary>
    /// <returns>
    ///   <para>Returns the currently set conversion delegate.</para>
    /// </returns>
    [RequiredByNativeCode]
    public static Lightmapping.RequestLightsDelegate GetDelegate()
    {
      return Lightmapping.s_RequestLightsDelegate;
    }

    /// <summary>
    ///   <para>Resets the light conversion delegate to Unity's default conversion function.</para>
    /// </summary>
    [RequiredByNativeCode]
    public static void ResetDelegate()
    {
      Lightmapping.s_RequestLightsDelegate = Lightmapping.s_DefaultDelegate;
    }

    [RequiredByNativeCode]
    internal static unsafe void RequestLights(
      Light[] lights,
      IntPtr outLightsPtr,
      int outLightsCount,
      AtomicSafetyHandle safetyHandle)
    {
      NativeArray<LightDataGI> nativeArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<LightDataGI>((void*) outLightsPtr, outLightsCount, Allocator.None);
      NativeArrayUnsafeUtility.SetAtomicSafetyHandle<LightDataGI>(ref nativeArray, safetyHandle);
      Lightmapping.s_RequestLightsDelegate(lights, nativeArray);
    }

    /// <summary>
    ///   <para>Delegate called when converting lights into a form that the baking backends understand.</para>
    /// </summary>
    /// <param name="requests">The list of lights to be converted.</param>
    /// <param name="lightsOutput">The output generated by the delegate function. Lights that should be skipped must be added to the output, initialized with InitNoBake on the LightDataGI structure.</param>
    public delegate void RequestLightsDelegate(
      Light[] requests,
      NativeArray<LightDataGI> lightsOutput);
  }
}
